import * as Sequelize from 'sequelize-typescript';
export interface IConfig{
    servers:Array<IServers>
}
export enum IServersType{
    http,
    https,
    websocket
}
export interface IDatabaseConfig{     
    host:string,
    port?:number,
    name:string,
    user?:string,
    pwd?:string,
    prefix?:string
}
export interface IServers{
    server_name:string|Array<string>//域名
    listen:number//监听端口
    root:string,//根目录
    proxy_pass:string,//转发路径
    static:string,//静态目录
    decode:Function,//解码函数
    encode:Function,//编码函数
    autoindex:boolean,//是否列出目录
    index:string|Array<string>,
    permission:Function,
    type:IServersType,
    view_path:string,
    database:IDatabaseConfig,
    _DBInstance?:any,
    session_config:{

    }
    backup?:{
        database?:{
            dir:string,
        },
    }
    redis?:IRedisConfig
    Controller:string
    Method:string
}
export interface ISessionConfig{
    handle:SessionHandleType,
    expire:number,
    config:IRedisConfig|IFileConfig
}
export enum SessionHandleType{
    Redis,
    File,
    MySql
}
export interface IFileConfig{

}
export interface IRelationConfig{
    name?:string,
    table:string,
    fields?:string|Array<string>|Function,
    fk?:string,
    pk?:string,
    relation?:string,
    where?:string
}
/**
 * MYSQL 表、视图结构定义
 */
export interface IDBMySqlTable{
    Auto_increment:number
    Avg_row_length:number
    Check_time:null|Date
    Checksum:null|any
    Collation:string
    Comment:string
    Create_options:string
    Create_time:Date
    Data_free:number
    Data_length:number
    Engine:string
    Index_length:number
    Max_data_length:number
    Name:string
    Row_format:string
    Rows:number
    Update_time:null|Date
    Version:number,
    Count?:number
}
/**
 * 查询方式
 */
export enum QueryTypes{
    SELECT= 'SELECT',
    INSERT= 'INSERT',
    UPDATE= 'UPDATE',
    BULKUPDATE= 'BULKUPDATE',
    BULKDELETE= 'BULKDELETE',
    DELETE= 'DELETE',
    UPSERT= 'UPSERT',
    VERSION= 'VERSION',
    SHOWTABLES= 'SHOWTABLES',
    SHOWINDEXES= 'SHOWINDEXES',
    DESCRIBE= 'DESCRIBE',
    RAW= 'RAW',
    FOREIGNKEYS= 'FOREIGNKEYS',
  };

export interface IDBMySqlProcedure{
    character_set_client:string
    collation_connection:string
    Comment:string
    Created:Date
    'Database Collation':string
    Db:string
    Definer:string
    Modified:Date
    Name:string
    Security_type:string
    Type:string
}

export interface IDBMySqlFunction{
    character_set_client:string
    collation_connection:string
    Comment:string
    Created:Date
    'Database Collation':string
    Db:string
    Definer:string
    Modified:Date
    Name:string
    Security_type:string
    Type:string
}

export interface IDBMySqlEvent{
    CREATED:Date
    DEFINER:string
    ENDS:null
    EVENT_CATALOG:string
    EVENT_COMMENT:string
    EVENT_DEFINITION:string
    EVENT_NAME:string
    EVENT_SCHEMA:string
    EVENT_TYPE:string
    EXECUTE_AT:null
    INTERVAL_FIELD:string
    INTERVAL_VALUE:string
    LAST_ALTERED:Date
    LAST_EXECUTED:null|Date
    ON_COMPLETION:string
    SQL_MODE:string
    STARTS:Date
    STATUS:string
}

export interface ICache{
    get(key:string):Promise<any>
    set(key:string,value:any,expire?:number):Promise<any>
}

export enum ErrorMessage{
    LoginRequired="LoginRequired",
    ParamRequired="ParamRequired",

}
export interface KoaCtxRqeust{
    url:string,
}
export interface KoaCtx{
    config:IServers,
    request:KoaCtxRqeust,
    host:string,
    session(key:string,value?:any):any,//session
}

export enum SessionOperate{
    SET_SESSION_ID,
    GET_SESSION_ID,
    DESTROY,
}

export interface ISessionHandler{
    set(key:string,value?:any)
    get(key:string):any
    create(id:string)
    destroy()
}

export interface IRedisConfig{
    host:string,
    port:number,
    password:string,
    db:number,
    family:number
}